// Check that lld properly handles merging multiple .res files.
// The inputs were generated with the following commands, using the original
// Windows rc.exe
// > rc /fo combined-resources.res /nologo combined-resources.rc
// > rc /fo combined-resources-2.res /nologo combined-resources-2.rc

// The object files were generated with GNU windres and MS cvtres.exe,
// > x86_64-w64-mingw32-windres combined-resources.res combined-resources.o
// > cvtres -machine:x64 -out:combined-resources-2.o combined-resources.res

# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj
# RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res \
# RUN:   %p/Inputs/combined-resources.res %p/Inputs/combined-resources-2.res

# RUN: llvm-readobj --coff-resources --file-headers --section-data %t.exe | \
# RUN:   FileCheck %s

# RUN: yaml2obj %p/Inputs/combined-resources.yaml -o %t-combined-resources.o
# RUN: yaml2obj %p/Inputs/combined-resources-2.yaml -o %t-combined-resources-2.o

# RUN: lld-link /lldmingw /out:%t-resobj.exe /entry:main %t.obj %p/Inputs/resource.res \
# RUN:   %t-combined-resources.o %t-combined-resources-2.o

// As input resources are traversed in a slightly different order, the
// RVAs of data blobs will end up slightly different, even if they are
// equivalent. Filter out such addresses from llvm-readobj's output,
// and compare the rest to make sure it is equivalent.

# RUN: llvm-readobj --coff-resources %t.exe | sed -E 's/(RVA|Address|File): .*//' > %t-orig.txt
# RUN: llvm-readobj --coff-resources %t-resobj.exe | sed -E 's/(RVA|Address|File): .*//' > %t-resobj.txt
# RUN: cmp %t-orig.txt %t-resobj.txt

CHECK:      ResourceTableRVA: 0x2000
CHECK-NEXT: ResourceTableSize: 0xC20
CHECK-DAG:  Resources [
CHECK-NEXT:   Total Number of Resources: 13
CHECK-DAG:  .rsrc Data (
CHECK-NEXT: 0000: 00000000 00000000 00000000 01000600  |................|
CHECK-NEXT: 0010: 38030080 48000080 02000000 60000080  |8...H.......`...|
CHECK-NEXT: 0020: 04000000 80000080 05000000 A0000080  |................|
CHECK-NEXT: 0030: 06000000 B8000080 09000000 D0000080  |................|
CHECK-NEXT: 0040: 0A000000 F0000080 00000000 00000000  |................|
CHECK-NEXT: 0050: 00000000 01000000 50030080 08010080  |........P.......|
CHECK-NEXT: 0060: 00000000 00000000 00000000 02000000  |................|
CHECK-NEXT: 0070: FE020080 20010080 0C030080 38010080  |.... .......8...|
CHECK-NEXT: 0080: 00000000 00000000 00000000 01000100  |................|
CHECK-NEXT: 0090: 2C030080 50010080 60380000 68010080  |,...P...`8..h...|
CHECK-NEXT: 00A0: 00000000 00000000 00000000 01000000  |................|
CHECK-NEXT: 00B0: 16030080 80010080 00000000 00000000  |................|
CHECK-NEXT: 00C0: 00000000 00000100 01000000 98010080  |................|
CHECK-NEXT: 00D0: 00000000 00000000 00000000 01000100  |................|
CHECK-NEXT: 00E0: E0020080 B0010080 0C000000 D0010080  |................|
CHECK-NEXT: 00F0: 00000000 00000000 00000000 01000000  |................|
CHECK-NEXT: 0100: 66030080 E8010080 00000000 00000000  |f...............|
CHECK-NEXT: 0110: 00000000 00000100 09040000 10020000  |................|
CHECK-NEXT: 0120: 00000000 00000000 00000000 00000100  |................|
CHECK-NEXT: 0130: 09040000 20020000 00000000 00000000  |.... ...........|
CHECK-NEXT: 0140: 00000000 00000100 09040000 30020000  |............0...|
CHECK-NEXT: 0150: 00000000 00000000 00000000 00000100  |................|
CHECK-NEXT: 0160: 090C0000 40020000 00000000 00000000  |....@...........|
CHECK-NEXT: 0170: 00000000 00000100 04080000 50020000  |............P...|
CHECK-NEXT: 0180: 00000000 00000000 00000000 00000100  |................|
CHECK-NEXT: 0190: 09040000 60020000 00000000 00000000  |....`...........|
CHECK-NEXT: 01A0: 00000000 00000100 09040000 70020000  |............p...|
CHECK-NEXT: 01B0: 00000000 00000000 00000000 00000200  |................|
CHECK-NEXT: 01C0: 09040000 80020000 04080000 90020000  |................|
CHECK-NEXT: 01D0: 00000000 00000000 00000000 00000100  |................|
CHECK-NEXT: 01E0: 09040000 A0020000 00000000 00000000  |................|
CHECK-NEXT: 01F0: 00000000 00000300 09040000 B0020000  |................|
CHECK-NEXT: 0200: 04080000 C0020000 07100000 D0020000  |................|
CHECK-NEXT: 0210: 002B0000 39000000 00000000 00000000  |.+..9...........|
CHECK-NEXT: 0220: C8230000 28030000 00000000 00000000  |.#..(...........|
CHECK-NEXT: 0230: F0260000 28030000 00000000 00000000  |.&..(...........|
CHECK-NEXT: 0240: D02A0000 30000000 00000000 00000000  |.*..0...........|
CHECK-NEXT: 0250: 182A0000 2E000000 00000000 00000000  |.*..............|
CHECK-NEXT: 0260: 482A0000 6C000000 00000000 00000000  |H*..l...........|
CHECK-NEXT: 0270: 80230000 2A000000 00000000 00000000  |.#..*...........|
CHECK-NEXT: 0280: B0230000 18000000 00000000 00000000  |.#..............|
CHECK-NEXT: 0290: 082C0000 18000000 00000000 00000000  |.,..............|
CHECK-NEXT: 02A0: B82A0000 18000000 00000000 00000000  |.*..............|
CHECK-NEXT: 02B0: 402B0000 36000000 00000000 00000000  |@+..6...........|
CHECK-NEXT: 02C0: 782B0000 43000000 00000000 00000000  |x+..C...........|
CHECK-NEXT: 02D0: C02B0000 42000000 00000000 00000000  |.+..B...........|
CHECK-NEXT: 02E0: 0E004D00 59004100 43004300 45004C00  |..M.Y.A.C.C.E.L.|
CHECK-NEXT: 02F0: 45005200 41005400 4F005200 53000600  |E.R.A.T.O.R.S...|
CHECK-NEXT: 0300: 43005500 52005300 4F005200 04004F00  |C.U.R.S.O.R...O.|
CHECK-NEXT: 0310: 4B004100 59000A00 54004500 53005400  |K.A.Y...T.E.S.T.|
CHECK-NEXT: 0320: 44004900 41004C00 4F004700 05002200  |D.I.A.L.O.G...".|
CHECK-NEXT: 0330: 45004100 54002200 0B005300 54005200  |E.A.T."...S.T.R.|
CHECK-NEXT: 0340: 49004E00 47004100 52005200 41005900  |I.N.G.A.R.R.A.Y.|
CHECK-NEXT: 0350: 0A004D00 59005200 45005300 4F005500  |..M.Y.R.E.S.O.U.|
CHECK-NEXT: 0360: 52004300 45000900 52004100 4E004400  |R.C.E...R.A.N.D.|
CHECK-NEXT: 0370: 4F004D00 44004100 54000000 00000000  |O.M.D.A.T.......|
CHECK-NEXT: 0380: 00000500 48006500 6C006C00 6F000000  |....H.e.l.l.o...|
CHECK-NEXT: 0390: 00000000 00000000 00000000 00000000  |................|
CHECK-NEXT: 03A0: 00000000 00000000 00000000 00000000  |................|
CHECK-NEXT: 03B0: 11000300 E7030000 0D004400 4C040000  |..........D.L...|
CHECK-NEXT: 03C0: 82001200 BC010000 28000000 10000000  |........(.......|
CHECK-NEXT: 03D0: 10000000 01001800 00000000 00030000  |................|
CHECK-NEXT: 03E0: C40E0000 C40E0000 00000000 00000000  |................|
CHECK-NEXT: 03F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0400: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0410: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0420: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0430: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0440: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0450: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0460: FFFFFFFF FF7F7F7F 7C7C7C78 78787575  |........|||xxxuu|
CHECK-NEXT: 0470: 75FFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |u...............|
CHECK-NEXT: 0480: FFFFFFFF FFFFFFFF FFFFFFFF 979797FF  |................|
CHECK-NEXT: 0490: FFFFFFFF FF838383 AAAAAADB DBDB7979  |..............yy|
CHECK-NEXT: 04A0: 79757575 FFFFFFFF FFFFFFFF FFFFFFFF  |yuuu............|
CHECK-NEXT: 04B0: FFFFFFFF FFFFFFFF FFFFFFFF 9C9C9C98  |................|
CHECK-NEXT: 04C0: 9898FFFF FF888888 DBDBDBB7 B7B77D7D  |..............}}|
CHECK-NEXT: 04D0: 7DFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |}...............|
CHECK-NEXT: 04E0: FFFFFFFF FFFFFFFF FFFFFFFF A0A0A09C  |................|
CHECK-NEXT: 04F0: 9C9C9393 93ADADAD F2F2F284 84848181  |................|
CHECK-NEXT: 0500: 81FFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0510: FFFFFFFF FFFFFFFF FFFFFFFF A4A4A4D7  |................|
CHECK-NEXT: 0520: D7D79D9D 9DD0D0D0 EEEEEE91 91918D8D  |................|
CHECK-NEXT: 0530: 8DFFFFFF FFFFFF81 81817E7E 7EFFFFFF  |..........~~~...|
CHECK-NEXT: 0540: FFFFFFFF FFFFFFFF FFFFFFFF A9A9A9F2  |................|
CHECK-NEXT: 0550: F2F2E5E5 E5E2E2E2 95959591 91918D8D  |................|
CHECK-NEXT: 0560: 8D898989 868686FF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0570: FFFFFFFF FFFFFFFF FFFFFFFF ADADADF2  |................|
CHECK-NEXT: 0580: F2F2E1E1 E1DFDFDF E7E7E7E4 E4E4BBBB  |................|
CHECK-NEXT: 0590: BB8E8E8E FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 05A0: FFFFFFFF FFFFFFFF FFFFFFFF B5B5B5F2  |................|
CHECK-NEXT: 05B0: F2F2E8E8 E8E7E7E7 EAEAEAC6 C6C69E9E  |................|
CHECK-NEXT: 05C0: 9EFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 05D0: FFFFFFFF FFFFFFFF FFFFFFFF B9B9B9F4  |................|
CHECK-NEXT: 05E0: F4F4ECEC ECEDEDED CBCBCBA7 A7A7FFFF  |................|
CHECK-NEXT: 05F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0600: FFFFFFFF FFFFFFFF FFFFFFFF BDBDBDF7  |................|
CHECK-NEXT: 0610: F7F7EFEF EFD0D0D0 AFAFAFFF FFFFFFFF  |................|
CHECK-NEXT: 0620: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0630: FFFFFFFF FFFFFFFF FFFFFFFF C1C1C1F7  |................|
CHECK-NEXT: 0640: F7F7D5D5 D5B6B6B6 FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0650: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0660: FFFFFFFF FFFFFFFF FFFFFFFF C4C4C4D9  |................|
CHECK-NEXT: 0670: D9D9BEBE BEFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0680: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0690: FFFFFFFF FFFFFFFF FFFFFFFF C8C8C8C5  |................|
CHECK-NEXT: 06A0: C5C5FFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 06B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 06C0: FFFFFFFF FFFFFFFF FFFFFFFF CBCBCBFF  |................|
CHECK-NEXT: 06D0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 06E0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 06F0: 28000000 10000000 10000000 01001800  |(...............|
CHECK-NEXT: 0700: 00000000 00030000 C40E0000 C40E0000  |................|
CHECK-NEXT: 0710: 00000000 00000000 FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0720: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0730: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0740: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0750: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0760: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0770: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0780: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0790: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 07A0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 07B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 07C0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 07D0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 07E0: FFFFFFFF A0E3A901 B31801B3 1801B318  |................|
CHECK-NEXT: 07F0: 01B31801 B31801B3 1861D06F FFFFFFFF  |.........a.o....|
CHECK-NEXT: 0800: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0810: FFFFFFFF 01B31800 D7331CDB 49DBF9E2  |.........3..I...|
CHECK-NEXT: 0820: 9BEFAF00 D73300D7 3301B318 FFFFFFFF  |.....3..3.......|
CHECK-NEXT: 0830: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0840: FFFFFFFF 01B31800 DE55F6FE F9DBFAE7  |.........U......|
CHECK-NEXT: 0850: FEFFFE86 EFAE00DE 5501B318 FFFFFFFF  |........U.......|
CHECK-NEXT: 0860: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0870: FFFFFFFF 01B31800 E676DBFB EC00E676  |.........v.....v|
CHECK-NEXT: 0880: 57EFA5FB FFFD55EE A401B318 FFFFFFFF  |W.....U.........|
CHECK-NEXT: 0890: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 08A0: FFFFFFFF 01B31800 ED9800ED 9800ED98  |................|
CHECK-NEXT: 08B0: 00ED9887 F7CFFEFF FF01B318 FFFFFFFF  |................|
CHECK-NEXT: 08C0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 08D0: FFFFFFFF 01B31800 F4BA00F4 BA00F4BA  |................|
CHECK-NEXT: 08E0: 00F4BA00 F4BA9CFB E401B318 FFFFFFFF  |................|
CHECK-NEXT: 08F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0900: FFFFFFFF 01B31800 FBDB00FB DB00FBDB  |................|
CHECK-NEXT: 0910: 00FBDB00 FBDB00FB DB01B318 FFFFFFFF  |................|
CHECK-NEXT: 0920: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0930: FFFFFFFF 9FE2A801 B31801B3 1801B318  |................|
CHECK-NEXT: 0940: 01B31801 B31801B3 1861D06F FFFFFFFF  |.........a.o....|
CHECK-NEXT: 0950: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0960: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0970: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0980: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0990: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09A0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09C0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09D0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09E0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 09F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0A00: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  |................|
CHECK-NEXT: 0A10: FFFFFFFF FFFFFFFF 00000000 00006400  |..............d.|
CHECK-NEXT: 0A20: 79007500 00000000 65007300 68006100  |y.u.....e.s.h.a.|
CHECK-NEXT: 0A30: 6C006100 00008000 66006B00 61006F00  |l.a.....f.k.a.o.|
CHECK-NEXT: 0A40: 79006100 00000000 0000C080 00000000  |y.a.............|
CHECK-NEXT: 0A50: 02000A00 0A00C800 2C010000 00005400  |........,.....T.|
CHECK-NEXT: 0A60: 65007300 74000000 01000250 00000000  |e.s.t......P....|
CHECK-NEXT: 0A70: 0A000A00 E6000E00 0100FFFF 82004300  |..............C.|
CHECK-NEXT: 0A80: 6F006E00 74006900 6E007500 65003A00  |o.n.t.i.n.u.e.:.|
CHECK-NEXT: 0A90: 00000000 00000150 00000000 42008600  |.......P....B...|
CHECK-NEXT: 0AA0: A1000D00 0200FFFF 80002600 4F004B00  |..........&.O.K.|
CHECK-NEXT: 0AB0: 00000000 00000000 11005800 A4000000  |..........X.....|
CHECK-NEXT: 0AC0: 0D004800 2E160000 82001200 BC010000  |..H.............|
CHECK-NEXT: 0AD0: 00000000 00006400 66006900 73006800  |......d.f.i.s.h.|
CHECK-NEXT: 0AE0: 00000000 65007300 61006C00 61006400  |....e.s.a.l.a.d.|
CHECK-NEXT: 0AF0: 00008000 66006400 75006300 6B000000  |....f.d.u.c.k...|
CHECK-NEXT: 0B00: 74686973 20697320 61207573 65722064  |this is a user d|
CHECK-NEXT: 0B10: 6566696E 65642072 65736F75 72636500  |efined resource.|
CHECK-NEXT: 0B20: 69742063 6F6E7461 696E7320 6D616E79  |it contains many|
CHECK-NEXT: 0B30: 20737472 696E6773 00000000 00000000  | strings........|
CHECK-NEXT: 0B40: 74686973 20697320 61207261 6E646F6D  |this is a random|
CHECK-NEXT: 0B50: 20626974 206F6620 64617461 20746861  | bit of data tha|
CHECK-NEXT: 0B60: 74206D65 616E7320 6E6F7468 696E6700  |t means nothing.|
CHECK-NEXT: 0B70: A9230E14 F4F60000 7A686534 20736869  |.#......zhe4 shi|
CHECK-NEXT: 0B80: 34207969 31676534 20737569 326A6931  |4 yi1ge4 sui2ji1|
CHECK-NEXT: 0B90: 20646520 73687534 6A75342C 207A6865  | de shu4ju4, zhe|
CHECK-NEXT: 0BA0: 34207969 34776569 347A6865 20736865  |4 yi4wei4zhe she|
CHECK-NEXT: 0BB0: 6E326D65 00A9230E 14F4F600 00000000  |n2me..#.........|
CHECK-NEXT: 0BC0: 44696573 20697374 2065696E 207A7566  |Dies ist ein zuf|
CHECK-NEXT: 0BD0: C3A46C6C 69676573 20426974 20766F6E  |..lliges Bit von|
CHECK-NEXT: 0BE0: 20446174 656E2C20 64696520 6E696368  | Daten, die nich|
CHECK-NEXT: 0BF0: 74732062 65646575 74657400 A9230E14  |ts bedeutet..#..|
CHECK-NEXT: 0C00: F4F60000 00000000 11000300 E7030000  |................|
CHECK-NEXT: 0C10: 0D004400 4C040000 82001200 BC010000  |..D.L...........|
CHECK-NEXT: )
